package server.simon;

import interfaces.AlarmClientCallbackInterface;
import interfaces.AlarmServerInterface;

import java.util.concurrent.BlockingQueue;

import org.apache.log4j.Logger;

import server.alarmThreads.OnlineCheckerThread;
import server.container.EinsatzAlarm;
import server.util.CacheTableNeuErstellen;
import de.root1.simon.annotation.SimonRemote;

@SimonRemote(value = { AlarmServerInterface.class })
public class AlarmServerInterfaceImpl implements AlarmServerInterface {

	/**
	 * 
	 */
	private static Logger logger = Logger.getLogger(AlarmServerInterfaceImpl.class);

	private static BlockingQueue<EinsatzAlarm> list = null;

	public AlarmServerInterfaceImpl(BlockingQueue<EinsatzAlarm> list2) {

		list = list2;
	}

	@Override
	public void addAlarm(AlarmClientCallbackInterface clientCallback, String[] info) {

		try {
			logger.trace("Alarm angekommen");
			list.put(new EinsatzAlarm(info));
		} catch (Exception e) {
			logger.error("", e);
		}
	}

	@Override
	public boolean istServerOK(AlarmClientCallbackInterface clientCallback) {
		return OnlineCheckerThread.getInstance().istServerOK();

	}

	@Override
	public void recreateCache() {

		Thread t = new Thread(new Runnable() {
			@Override
			public void run() {
				CacheTableNeuErstellen.main(null);
			}
		});
		t.start();
	}

}
